'use strict';

var headers ={
  // 'Content-Type': 'application/x-www-form-urlencoded'
  // ,'X-Requested-With':'application/x-www-form-urlencoded,text/javascript'
}

angular.module('mdNote.services',['ngResource'])

// 读取
.factory('MdReader',['$resource',function($resource){
  var md = {};
  var msg = {};

  var res = $resource(':path', {path:'@path'}, {
        'get':{method:'GET',cache:true}
        ,'save':{method:'POST'}
        ,'update':{method:'PUT'}
      });
  // var updateRe = $resource('/edit/:path',{path:'@path'});
  // var createRe = $resource('/create');

  return{
    one:function(fname) {
      md = res.get({path:fname});
      return md;
    }
    ,update:function(data){
      msg = res.save({path:data.mdpath},data);
      return msg;
    }
    ,save:function(data){
      msg = res.save(data);
      return msg;
    }
  };
}])

// 菜单
.factory('Menus',['$resource',function($resource){
  var menus = [];
  var fmenus = [];
  var baseUrl = "/menus";

  var getRe = $resource("/menus/:path", {path:'@path'},{
    'query':{method:'GET',isArray:true,cache:true}
  });

  return {
    all:function(){
      menus = getRe.query();
      return menus;
    }
    ,find:function(fpath){
      fmenus = getRe.query({path:fpath});
      return fmenus;
    }
    ,refreshAll:function(){
      menus = [];
    }
    ,destroy:function(){
      menus = [];
    }
  }
}])

;
